#!/bin/sh

show_logs() {
  if [ -n "$1" ]
  then
    find "$TARGET_PATH/logs/$(basename "$SPEC_NAME")" -name '*.log' -type f \
      | while read LOG
      do
        echo
        echo ------------------------------------------------------------------
        echo "$LOG"
        echo ------------------------------------------------------------------
        cat "$LOG"
        echo ------------------------------------------------------------------
        echo
      done
    return
  fi
  find "$TARGET_PATH/logs" -name '*.log' -type f \
    | grep -v -F 'logs/results.log' | while read LOG
    do
      echo
      echo ------------------------------------------------------------------
      echo "$LOG"
      echo ------------------------------------------------------------------
      cat "$LOG"
      echo ------------------------------------------------------------------
      echo
    done
}

show_failed_logs() {
  find "$TARGET_PATH" -name '*.failed' -type f \
    | while read FAILED
      do
        show_logs "$(basename "$FAILED" | sed 's/^\([^.]\+\)\.failed/\1/')"
      done
}